﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Areas/Instructor/Views/Shared/_Layout.cshtml";
}
<div id="varify" style="display: none">
    <div class="container-fluid">
        <div class="row-fluid">
            <div class="well span20 center login-box">
                <form action="../Instructor/home/ActivationMail">
                    <div class="alert alert-info" id="reg">
                        <span id="scmsg"></span>
                    </div>
                    <div class="alert alert-info">
                        <p>Please Check Your MailBox , </p>
                        <p>And Complete the Process of Varification</p>
                    </div>
                    <div>
                        <button title="Resend" id="btnresend" class="btn btn-primary" onclick="resend();">Resend Mail</button>
                        <div>In case of Mail not Received or Deleted</div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<div class="pull-right col-md-6" style="margin: 0px;">
    <div class="form-vertical" role="form">
        <div class="form-group" id="divSubject">
            <label class="col-lg-2 control-label" style="text-align: right">Subject </label>
            <div class="col-lg-4">
                <select id="SubjectID" class="form-control">
                    <option value="0">--Select--</option>
                </select>
            </div>
        </div>
        <div class="form-group" id="divTopic">
            <label class="col-lg-2 control-label" style="text-align: right">Topic</label>
            <div class="col-lg-4">
                <select id="TopicID" class="form-control ">
                    <option value="0">--Select--</option>
                </select>
            </div>
        </div>
    </div>
</div>
<div class="clearfix"></div>
<div class="widget">
    <div class="widget-head">OverAll Performance For Subject: <span id="subject"></span><span id="topic"></span></div>
    <div class="widget-content">
        <div class="padd">
            <canvas id="ChartInstructor" height="300" width="1024"></canvas>
            <div id="labelstud" style="width: 100%; text-align: center;">STUDENT'S</div>
            <div id="divMsgIndex"></div>
        </div>
    </div>
    <div class="col-lg-6">
        <div class="widget">
            <div class="widget-head">Attempt Ratio For Subject: <span id="subject1"></span><span id="topic1"></span></div>
            <div class="widget-content">
                <div class="padd">
                    <div id="divMsgIndex1"></div>
                    <canvas id="pie" height="250" width="400"></canvas>
                </div>
            </div>
        </div>
    </div>
</div>
@section scripts{
    <script type="text/javascript">
        function vall() {
            return (Math.floor(Math.random() * 156) + 50).toString();
        }
        function rgba() {
            return 'rgba(' + vall() + ',' + vall() + ',' + vall() + ',' + 0.9 + ')';
        }
        function varify() {
            $.getJSON("/Instructor/Home/Isvarify", { dt: "test" },
                function (cnt) {
                    if (cnt != null && cnt == 1) {
                        $("#varify").css({ "display": "Block" });
                    }
                });
            $.getJSON("/Instructor/Home/fillSub", { dt: "test" },
                 function (classesData) {
                     var select = $("#SubjectID");
                     $.each(classesData, function (index, itemData) {
                         if (index == 0) {
                             select.append($('<option/>', {
                                 value: itemData.Value,
                                 text: itemData.Text,
                                 Selected: true
                             }));
                             $.getJSON("/Student/MyTest/Topics", { SubjectID: itemData.Value },
                                  function (classesData) {
                                      var select = $("#TopicID");
                                      select.empty();
                                      select.append($('<option/>', {
                                          value: 0,
                                          text: "--Select --"
                                      }));
                                      $.each(classesData, function (index, itemData) {
                                          select.append($('<option/>', {
                                              value: itemData.Value,
                                              text: itemData.Text
                                          }));
                                      });
                                  });
                             createChart();
                         }
                         else {
                             select.append($('<option/>', {
                                 value: itemData.Value,
                                 text: itemData.Text,
                                 Selected: false
                             }));
                         }
                     });
                 });
        }
        function resend() {
            $.getJSON("/Instructor/Home/ActivationMail", { dt: "test" },
            function (st) {
                if (st != null && st == 1) {
                }
            });
        }
        function createChart() {
            $("#ChartInstructor").show();
            $('#labelstud').show();
            $("#pie").show();
            var cht = document.getElementById('pie');
            var ctx = cht.getContext('2d');
            var myPieChart = new Chart(ctx).Pie();
            var cht = document.getElementById('ChartInstructor');
            var ctx = cht.getContext('2d');
            var SubjectID = $("#SubjectID").val();
            var TopicID = $("#TopicID").val();
            var CallFor = (TopicID > 0) ? 1 : 2;
            $('#subject').text((SubjectID == 0) ? '' : $("#SubjectID option:selected").text());
            $('#topic').text((TopicID == 0) ? '' : " And Topic :" + $("#TopicID option:selected").text());
            $('#subject1').text((SubjectID == 0) ? '' : $("#SubjectID option:selected").text());
            $('#topic1').text((TopicID == 0) ? '' : " And Topic :" + $("#TopicID option:selected").text());
            $.ajax({
                url: "/Instructor/Home/InstructorBarData?SubjectID=" + SubjectID + "&TopicID=" + TopicID + "&CallFor=" + CallFor,
                type: "POST",
                success: function (data) {
                    if (data != null && data.labels.length > 0) {
                        showMsg('divMsgIndex', '', '');
                        showMsg('divMsgIndex1', '', '');
                        // For Bar Control Data Binding 
                        var data1 = {
                            "datasets":
                                [{
                                    fillColor: "rgba(26,174,243,0.6)",
                                    strokeColor: "rgba(151,187,205,0.5)",
                                    highlightFill: "rgba(9,147,211,0.9)",
                                    highlightStroke: "rgba(151,187,205,1)",
                                    data: data.datasets.data
                                }],
                            labels: data.labels
                        }
                        var step = 10;
                        var max = 100
                        var start = 40;
                        var barChart = new Chart(ctx).Bar(data1, {
                            scaleOverride: true,
                            scaleSteps: Math.ceil((max) / step),
                            scaleStepWidth: step,
                            scaleStartValue: start,
                            scaleStartValue: 0,
                            responsive: true
                        });
                    }
                    else {
                        $("#ChartInstructor").hide();
                        $("#pie").hide();
                        $('#labelstud').hide();
                        showMsg('divMsgIndex', '<b>No Data Available</b>', 'info');
                        showMsg('divMsgIndex1', '<b>No Data Available</b>', 'info');
                    }
                    //End Bar Control Data Binding
                    //DATA Binding For PIE Diagram
                    for (var i = 0; i < data.datasets.piedata.length; i++) {
                        var col = rgba();
                        var colnew = col.replace(/0.9/i, "0.7");
                        myPieChart.addData({
                            value: Math.round(data.datasets.piedata[i]),
                            color: col,
                            highlight: colnew,
                            label: data.Pielabels[i],
                            labelColor: 'White',
                            labelFontSize: '18'
                        });
                    }
                    //End OF DATA Binding For PIE Chart
                },
                error: function (data) {
                }
            });
        }
        $(document).ready(function () {
            //$("#SubjectID").val(1);
            //$("#ChartInstructor").hide();
            //$("#pie").hide();
            //$('#labelstud').hide();
           // showMsg('divMsgIndex', '<b>No Data Available</b>', 'info');
           // showMsg('divMsgIndex1', '<b>No Data Available</b>', 'info');
            var msg = '@Session["sc"]'
            if (msg.length > 3) {
                $("#scmsg").text('@Session["sc"]');
            }
            else {
                $("#reg").hide();
            }
            $('#h2Title').html("<i class='fa fa-home'></i> Deshboard");
            $('#aTitle').html("Deshboared");
            $('#liDeshboard').addClass("open");
            varify();
            var notice = '@TempData["notice"]';
            if (notice != '' || notice != undefined || notice != null) {
                $('#notice').show();
                $('#notice').html(notice);
                setTimeout("$('#notice').hide(); ", 3000);
            }
            else {
                $('#notice').hide();
            }

            $("#TopicID").change(function (e) {
                createChart();
            });

            $("#SubjectID").change(function (e) {
                var SubjectID = $(this).val();
                $.getJSON("/Student/MyTest/Topics", { SubjectID: SubjectID },
                       function (classesData) {
                           var select = $("#TopicID");
                           select.empty();
                           select.append($('<option/>', {
                               value: 0,
                               text: "--Select --"
                           }));
                           $.each(classesData, function (index, itemData) {
                               select.append($('<option/>', {
                                   value: itemData.Value,
                                   text: itemData.Text
                               }));
                           });
                           createChart();
                       });
                return false;
            });
        });
    </script>
}
